<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>原型式继承</title>
</head>
<body>
    <h1>原型式继承</h1>
</body>
<script type="text/javascript">
    function createObj(o) {
        function F(){}
        F.prototype = o;
        return new F();
    }

    var person = {
        name: 'kevin',
        friends: ['daisy', 'kelly']
    }
    
    var person1 = createObj(person);
    var person2 = createObj(person);
    
    person1.name = 'person1';
    console.log(person1.name)
    console.log(person2.name); // kevin
 
    person1.friends.push('taylor');
    console.log(person1.friends); // ["daisy", "kelly", "taylor"]
    console.log(person2.friends); // ["daisy", "kelly", "taylor"]

    console.log('person1',person1);
    console.log('person2',person2)


    // es6
    var People = {
        name: "Nicholas",
        friends: ["Shelby", "Court", "Van"]
    };
    var anotherPeople = Object.create(People);
    anotherPeople.name = "Greg";
    anotherPeople.friends.push("Rob"); 
    // console.log('anotherPeople',anotherPeople)

</script>
</html>